package cn.buddha.jesj.util;

import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName StringTest
 * @Author 友野浩二
 * @Date 2019/11/28 19:55
 * @Description String测试
 * @Version 1.0
 */
public class StringTest {

    private static Map<Integer, String> map = new HashMap<>();

    static {
        map.put(1, "a");
        map.put(2, "b");
        map.put(3, "c");
        map.put(4, "d");
        map.put(5, null);
    }

    public static void main(String[] args) {
        String str = "a,b,c,d,ef,g,,h,,";

        String[] strs = str.split(",", -1);
        System.out.println(strs.length);// 10
        System.out.println(Arrays.toString(strs));// ["a", "b", "c", "d", "ef", "g", "", "h", "", ""]

        // 1- 不剔除空格
        String[] strs2 = StringUtils.delimitedListToStringArray(str, ",");
        System.out.println(strs2.length);// 10
        System.out.println(Arrays.toString(strs2));// ["a", "b", "c", "d", "ef", "g", "", "h", "", ""]

        // 2- 剔除空格
//        String str2 = "a,b,c,d,ef,g,,h,,";
////        String str2 = null;
//        String[] strs2 = com.sun.deploy.util.StringUtils.splitString(str2, ",");// maven编译报错: 程序包com.sun.deploy.util不存在
//        System.out.println(strs2.length);// 7
//        System.out.println(Arrays.toString(strs2));// ["a", "b", "c", "d", "ef", "g", "h"]

        if (map.containsKey(5)) {
            System.out.println("哈哈哈");
        }

        System.out.println(map.get(8));// map没有key，返回null
        System.out.println(map.get(5));
        if (map.get(5) != null && !"".equals(map.get(5))) {
            System.out.println("呵呵呵");
        }
        System.out.println("".equals(map.get(8)));
    }

}
